<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name', 50);
            $table->integer('price');
            $table->unsignedInteger('class_id');
            $table->integer('amount')->default(0);
            $table->string('image', 50);
            $table->string('description', 140)->default('暂无商品描述')->nullable();
            $table->timestamps();
        });

        Schema::table('products', function($table) {
            $table->foreign('class_id')->references('id')->on('classifications')->onDelete('cascade');
        });


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('products');
    }
}
